The present disclosure generally relates to computer systems, and more specifically, to techniques for thread scheduling on a processing core based on a number of instructions a thread has executed.
The basic structure of a conventional computer system includes a system bus or a direct channel that connects one or more processors to input/output (I/O) devices (such as a display monitor, keyboard and mouse), a permanent memory device for storing the operating system and user programs, (such as a magnetic hard disk), and a temporary memory device that is utilized by the processors to carry out program instructions (such as random access memory or “RAM”). When a user program runs on a computer, the computer's operating system (OS) may first load the program files into system memory. The program files could include data objects and instructions for handling the data and other parameters which may be input during program execution.
Generally, the operating system creates a process to run a user program. A process is a set of resources, including (but not limited to) values in RAM, process limits, permissions, registers, and at least one execution stream. Such an execution stream is commonly termed a “thread.” The utilization of threads in operating systems and user applications is well known. Threads allow multiple execution paths within a single address space (the process context) to run concurrently on a processor. This “multithreading” increases throughput and modularity in multiprocessor and uniprocessor systems alike. For example if a thread must wait for the occurrence of an external event, then it stops and the computer processor executes another thread of the same or different computer program to optimize processor utilization. Multithreaded programs also can exploit the existence of multiple processors by running the application program in parallel. Parallel execution reduces response time and improves throughput in multiprocessor systems.
Additionally, a scheduler can be configured to manage the execution of multiple threads on a multithreaded processor. Generally speaking, the act of suspending a first thread that is executing on the processor and beginning the execution of a second thread on the processor is known as context switching. Here, a context represents the contents of the processor's registers and program counter at some point in time. A register is a small amount of memory (typically very fast memory) inside of a processing unit (as opposed to the slower Random Access Memory (RAM) outside of the processing unit) that is used to speed the execution of computer programs by providing quick access to commonly used values. For instance, such a register could store values that are used in the midst of a calculation on the processing unit. A program counter is a specialized register that indicates the position of the processing unit in its instruction sequence. Such a program counter may hold the address of the instruction being executed or could hold the address of the next instruction to be executed, depending on the specific system.
More specifically, context switching may be described as the kernel (i.e., the core of an operating system) performing the following activities with regard to processes (including threads) on the processing unit: (1) suspending the progression of one process and storing the processing unit's state (i.e., the context) for that process somewhere in memory, (2) retrieving the context of the next process from memory and restoring it in the processing unit's registers and (3) returning to the location indicated by the program counter (i.e., returning to the line of code at which the process was interrupted) in order to resume the process. A context switch may be described as the kernel suspending execution of one process on the processing unit and resuming execution of some other, previously suspended process. Put another way, context switching refers to suspending progression of a process in order to advance the progression (with regard to execution) of a second process.